package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfOriginalDataFilter;
import com.yuandian.api.management.validate.SelectFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfOriginalDataFilterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * 原始样包过滤配置表-Controller
 * @author zfsn
 * @date 2023-4-12
 */
@Api(tags = "原始数据包分析-捕获规则配置")
@RestController
@RequestMapping("/originalDataFilter")
public class ConfOriginalDataFilterController {

	@Autowired
	private ConfOriginalDataFilterService confOriginalDataFilterService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfOriginalDataFilter>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confOriginalDataFilterService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confOriginalDataFilter 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	public R<Page<ConfOriginalDataFilter>> listPage(@RequestBody ConfOriginalDataFilter confOriginalDataFilter) {
		return R.ok(confOriginalDataFilterService.listPage(confOriginalDataFilter));
	}

	/**
	 * 新增数据
	 * @param confOriginalDataFilter 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增识别关键字表数据")
	@PostMapping("/save")
	public R<String> saveConfig(@RequestBody ConfOriginalDataFilter confOriginalDataFilter) {
		return confOriginalDataFilterService.saveConfig(confOriginalDataFilter);
	}

	/**
	 * 通过主键更新数据
	 * @param confOriginalDataFilter 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新识别关键字表数据")
	@PutMapping
	public R updateById(@RequestBody ConfOriginalDataFilter confOriginalDataFilter) {
		return confOriginalDataFilterService.updateConfigById(confOriginalDataFilter);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除识别关键字表数据")
	@DeleteMapping("/delete/{ids}")
	public R removeByIds(@PathVariable("ids") List<Integer> ids){
		return confOriginalDataFilterService.deleteByIds(ids);
	}

	/**
	 * 修改原始包捕获规则  禁用启用
	 *
	 * @param confOriginalDataFilter 参数
	 * @return Result
	 */
	@PostMapping("/updateStatus")
	@ApiOperation(value = "修改捕获规则状态", notes = "修改捕获规则状态")
	public R updateStatus(@RequestBody ConfOriginalDataFilter confOriginalDataFilter) {
		return confOriginalDataFilterService.updateStatusByIds(confOriginalDataFilter);
	}


	/**
	 * 保存原始包捕获规则
	 *
	 * @param confOriginalDataFilter 参数
	 * @return Result
	 */
	@ApiOperation(value = "同步捕获规则", notes = "同步捕获规则")
	@PostMapping("/sendFilterRule")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "body", required = true, dataTypeClass = Integer.class)
	})
	public R sendFilterRule(@RequestBody @ApiIgnore @Validated(SelectFlag.class) ConfOriginalDataFilter confOriginalDataFilter) {
		return confOriginalDataFilterService.syncFilterRule(confOriginalDataFilter);
	}

	/**
	 * 查询原始包捕获规则数据
	 *
	 * @return Result
	 */
	@GetMapping("/findName")
	@ApiOperation(value = "查询原始包捕获规则数据", notes = "查询原始包捕获规则数据")
	public R<List<Map<String, Object>>> findName() {
		return R.ok(confOriginalDataFilterService.findName());
	}
}
